package org.demo.cnck.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.demo.cnck.controller.error.BussinessException;
import org.demo.cnck.dao.domain.Pet;
import org.demo.cnck.dao.repository.PetRepository;
import org.demo.cnck.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by cdyoue on 2018/11/20.
 */
@Service
public class PetServiceImpl implements PetService {
    @Autowired
    private PetRepository petRepository;

    @Override
    public List<Pet> findAll(String petname, Long id) {

        Pet pet = new Pet();
        if (StringUtils.isNoneBlank(petname)) {
            pet.setPetname(petname);
        }

        if (id != null) {
            pet.setId(id);
        }
        Example<Pet> example = Example.of(pet);
        return petRepository.findAll(example);
    }

    @Override
    public void save(Pet pet) {
        petRepository.save(pet);
    }

    @Override
    public void del(Long id) {
        petRepository.delete(id);
    }
}
